package com.openbravo.pos.config;

import com.openbravo.data.user.DirtyManager;
import com.openbravo.pos.forms.AppConfig;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.util.AltEncrypter;

import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.text.Document;

public class JPanelConfigERP extends JPanel
  implements PanelConfig
{
  private DirtyManager dirty = new DirtyManager();
  private JLabel jLabel1;
  private JLabel jLabel2;
  private JLabel jLabelId;
  private JLabel jLabelName;
  private JLabel jLabelProperties;
  private JPanel jPanel1;
  private JTextField jTextField1;
  private JTextField jTextField2;
  private JLabel jlabelUrl;
  private JTextField jtxtId;
  private JTextField jtxtName;
  private JPasswordField jtxtPassword;
  private JTextField jtxtUrl;

  public JPanelConfigERP()
  {
    initComponents();
    this.jTextField1.getDocument().addDocumentListener(this.dirty);
    this.jTextField2.getDocument().addDocumentListener(this.dirty);
    this.jtxtId.getDocument().addDocumentListener(this.dirty);
    this.jtxtName.getDocument().addDocumentListener(this.dirty);
    this.jtxtPassword.getDocument().addDocumentListener(this.dirty);
    this.jtxtUrl.getDocument().addDocumentListener(this.dirty);
  }

  public boolean hasChanged()
  {
    return this.dirty.isDirty();
  }

  public Component getConfigComponent()
  {
    return this;
  }

  public void loadProperties(AppConfig paramAppConfig)
  {
    this.jtxtUrl.setText(paramAppConfig.getProperty("erp.URL"));
    this.jtxtId.setText(paramAppConfig.getProperty("erp.id"));
    this.jTextField2.setText(paramAppConfig.getProperty("erp.pos"));
    this.jTextField1.setText(paramAppConfig.getProperty("erp.org"));
    String str1 = paramAppConfig.getProperty("erp.user");
    String str2 = paramAppConfig.getProperty("erp.password");
    if ((str1 != null) && (str2 != null) && (str2.startsWith("crypt:")))
    {
      AltEncrypter localAltEncrypter = new AltEncrypter("cypherkey" + str1);
      str2 = localAltEncrypter.decrypt(str2.substring(6));
    }
    this.jtxtName.setText(str1);
    this.jtxtPassword.setText(str2);
    this.dirty.setDirty(false);
  }

  public void saveProperties(AppConfig paramAppConfig)
  {
    paramAppConfig.setProperty("erp.URL", this.jtxtUrl.getText());
    paramAppConfig.setProperty("erp.id", this.jtxtId.getText());
    paramAppConfig.setProperty("erp.pos", this.jTextField2.getText());
    paramAppConfig.setProperty("erp.org", this.jTextField1.getText());
    paramAppConfig.setProperty("erp.user", this.jtxtName.getText());
    AltEncrypter localAltEncrypter = new AltEncrypter("cypherkey" + this.jtxtName.getText());
    paramAppConfig.setProperty("erp.password", "crypt:" + localAltEncrypter.encrypt(new String(this.jtxtPassword.getPassword())));
    this.dirty.setDirty(false);
  }

  private void initComponents()
  {
    this.jPanel1 = new JPanel();
    this.jlabelUrl = new JLabel();
    this.jtxtUrl = new JTextField();
    this.jLabelId = new JLabel();
    this.jtxtId = new JTextField();
    this.jLabel1 = new JLabel();
    this.jTextField1 = new JTextField();
    this.jLabel2 = new JLabel();
    this.jTextField2 = new JTextField();
    this.jLabelName = new JLabel();
    this.jtxtName = new JTextField();
    this.jLabelProperties = new JLabel();
    this.jtxtPassword = new JPasswordField();
    this.jPanel1.setBorder(BorderFactory.createTitledBorder(AppLocal.getIntString("label.configerp")));
    this.jlabelUrl.setText(AppLocal.getIntString("label.erpurl"));
    this.jLabelId.setText(AppLocal.getIntString("label.erpid"));
    this.jLabel1.setText(AppLocal.getIntString("label.erporg"));
    this.jLabel2.setText(AppLocal.getIntString("label.erppos"));
    this.jLabelName.setText(AppLocal.getIntString("label.erpuser"));
    this.jLabelProperties.setText(AppLocal.getIntString("label.erppassword"));
    GroupLayout localGroupLayout1 = new GroupLayout(this.jPanel1);
    this.jPanel1.setLayout(localGroupLayout1);
    localGroupLayout1.setHorizontalGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout1.createSequentialGroup().addContainerGap().addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout1.createSequentialGroup().addComponent(this.jlabelUrl, -2, 130, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jtxtUrl, -2, 380, -2)).addGroup(localGroupLayout1.createSequentialGroup().addComponent(this.jLabelId, -2, 130, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jtxtId, -2, 180, -2)).addGroup(localGroupLayout1.createSequentialGroup().addComponent(this.jLabel1, -2, 130, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jTextField1, -2, 180, -2)).addGroup(localGroupLayout1.createSequentialGroup().addComponent(this.jLabel2, -2, 130, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jTextField2, -2, 180, -2)).addGroup(localGroupLayout1.createSequentialGroup().addComponent(this.jLabelName, -2, 130, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jtxtName, -2, 180, -2)).addGroup(localGroupLayout1.createSequentialGroup().addComponent(this.jLabelProperties, -2, 130, -2).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jtxtPassword, -2, 180, -2))).addContainerGap(201, 32767)));
    localGroupLayout1.setVerticalGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout1.createSequentialGroup().addContainerGap().addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jlabelUrl).addComponent(this.jtxtUrl, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabelId).addComponent(this.jtxtId, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel1).addComponent(this.jTextField1, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel2).addComponent(this.jTextField2, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabelName).addComponent(this.jtxtName, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabelProperties).addComponent(this.jtxtPassword, -2, -1, -2)).addContainerGap(16, 32767)));
    GroupLayout localGroupLayout2 = new GroupLayout(this);
    setLayout(localGroupLayout2);
    localGroupLayout2.setHorizontalGroup(localGroupLayout2.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout2.createSequentialGroup().addContainerGap().addComponent(this.jPanel1, -1, -1, 32767).addContainerGap()));
    localGroupLayout2.setVerticalGroup(localGroupLayout2.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout2.createSequentialGroup().addContainerGap().addComponent(this.jPanel1, -2, -1, -2).addContainerGap(15, 32767)));
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.config.JPanelConfigERP
 * JD-Core Version:    0.6.0
 */